function playAudio(){
    
    if(window.HTMLAudioElement){
        
        var audio = document.getElementById("myMusic");
        var mainControl=document.getElementById("mainControl")
        var stopControl=document.getElementById("stopControl")
        mainControl.style.display="none";
        stopControl.style.display="";
        audio.play();

        

        //TimeSpan();
        audio.addEventListener("timeupdate",function(){
            var audio = document.getElementById("myMusic");
            var processYet=0;
            processYet =audio.currentTime/audio.duration*500;
            document.getElementById("processYet").style.width=processYet+"px"
            var currentTime = timeDispose(audio.currentTime);
            var TimeAll = timeDispose(audio.duration);
            document.getElementById("songTime").innerHTML=currentTime+
            "&nbsp;|&nbsp;"+TimeAll;
        });   
    }
}
var content=document.getElementsByClassName("content")[0];
var txt=document.getElementById("txt");
var lrc=txt.value;
var lrclist=lrc.split("[");
lrclist.forEach(function(el,index,self){
    var arr=el.split("]")
    var singler=arr[1];
    var time=arr[0];
      
    var p=document.createElement("p");
    if(singler){
        //time.split(":")[0]+time.split(":")[1];
       var min= time.split(":")[0]*60+parseInt(time.split(":")[1]);
        p.innerHTML=singler;
        p.className="time-"+min;
        content.appendChild(p);
    } 
});

var p=document.getElementsByTagName("p");

var audio = document.getElementById("myMusic");
audio.addEventListener("timeupdate",function(){
    //console.log(this.currentTime);
    var cur = parseInt(this.currentTime);
    if(document.getElementsByClassName("time-"+cur).length){
        Array.prototype.forEach.call(p,function(el){
            el.style.cssText="color:#000000; font-size:12px"
        });
        document.getElementsByClassName("time-"+cur)[0].style.cssText=
        "color:red;font-size:18px;"
    }
    
});

function pauseAudio(){
    if(window.HTMLAudioElement){
        var audio = document.getElementById("myMusic");
        var mainControl=document.getElementById("mainControl")
        var stopControl=document.getElementById("stopControl")
        stopControl.style.display="none";
        mainControl.style.display="";
        audio.pause();
    }
}
function rewindAudio(){
    if(window.HTMLAudioElement){
        var audio = document.getElementById("myMusic");
        audio.currentTime -=15.0;

    }
}
function forwardAudio(){
    if(window.HTMLAudioElement){
        var audio = document.getElementById("myMusic");
        audio.currentTime +=15.0;
        
    }
}
function TimeAll(){
    if(window.HTMLAudioElement){
        var audio = document.getElementById("myMusic");
        return audio.duration;
        
    }
}
function voiceEmp(){
    if(window.HTMLAudioElement){
        var audio = document.getElementById("myMusic");
        var voidProcessYet=document.getElementById("voidProcessYet");
        voidProcessYet.style.width="0px";
        audio.volume=0;
        
    }
}
function voiceFull(){
    if(window.HTMLAudioElement){
        var audio = document.getElementById("myMusic");
        var voidProcessYet=document.getElementById("voidProcessYet");
        voidProcessYet.style.width="66px";
        audio.volume=1;
        
    }
}

function TimeSpan(){
    if(window.HTMLAudioElement){
        var audio = document.getElementById("myMusic");
        var processYet=0;
        setInterval(function(){
            processYet =audio.currentTime/audio.duration*500;
            document.getElementById("processYet").style.width=processYet+"px"
            var currentTime = timeDispose(audio.currentTime);
            var TimeAll = timeDispose(audio.duration);
            document.getElementById("songTime").innerHTML=currentTime+
            "&nbsp;|&nbsp;"+TimeAll;
        },1000); 
    }
}

function timeDispose(number){
    var minute=parseInt(number/60);
    var second=parseInt(number%60);
    minute = minute>=10? minute:"0"+minute;
    second = second>=10? second:"0"+second;
    return minute + ":"+second;
}


function audioProcess(){
    var process=document.getElementById("process");
    var processStart=process.offsetLeft;
    var currentProcess=event.clientX-processStart;
    var processAll=process.style.width;
    var processAllint=processAll.split("px")[0];//分割数字和字符split
    var audio=document.getElementById("myMusic")
    audio.currentTime=currentProcess/processAllint*audio.duration;
}

function voidProcess(){
    var process=document.getElementById("voidProcess");
    var processStart=process.offsetLeft;
    var currentProcess=event.clientX-processStart;
    var processAll=process.style.width;
    var processAllint=processAll.split("px")[0];//分割数字和字符split
    var audio=document.getElementById("myMusic")
    audio.volume=parseFloat(currentProcess/processAllint);  
    var voidProcessYet=document.getElementById("voidProcessYet");
    voidProcessYet.style.width=currentProcess+"px";
}

